<!-- menu表单弹窗 -->
<form id="menu-form" lay-filter="menu-form" class="layui-form model-form" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名</label>
        <div class="layui-input-block">
            <input type="text" name="id" class="layui-hide">
            <input name="name" placeholder="请输入菜单名" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">路径</label>
        <div class="layui-input-block">
            <input name="path" placeholder="请输入路径" type="text" class="layui-input" lay-verify="required"
                   required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限</label>
        <div class="layui-input-block">
            <input name="auth" placeholder="请输入权限" type="text" class="layui-input" maxlength="20"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">链接</label>
        <div class="layui-input-block">
            <input name="url" placeholder="请输入链接" type="text" class="layui-input" maxlength="20"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-block">
            <input name="icon" placeholder="请输入图标" type="text" class="layui-input" maxlength="20"/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="menu-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;

        var Menuform = {
            init:function(){
                var data = admin.getTempData('t_menu');
                Menuform.setFormValue(data);
                Menuform.subimtFormBind();
            }
            ,
            setFormValue:function(data){
                if(data) $('#menu-form').attr('method', 'put');
                form.val('menu-form',data);
            }
            ,
            subimtFormBind:function(){
                form.on('submit(menu-form-submit)', function(data){
                    
                    console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                    Menuform.postForm(data.field);
                    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                });
            }
            ,
            postForm:function(_data){
                admin.req('http://localhost/service-system/Menu', _data, function (data) {
                    layer.closeAll('loading');
                    if (data.code === 10000) {
                        layer.msg(data.msg, {icon: 1});
                        console.log(1);
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }, $('#menu-form').attr('method'));
            }
        };

        Menuform.init();
        form.render();
    });
</script>